/**
 * Created by aperry on 27/06/2014.
 */
var commonDirectives = angular.module('assetPlusApp.commonDirectives', []);

commonDirectives.directive('cvDate', function () {
    return {
        restrict: 'E',
        scope: {
            dt: "=field",

        },
        templateUrl: 'partials/common/date.html',
        link: function(scope, element, attrs){
            console.log('cvDate', scope.field);
            scope.$watch('dt', function(newValue, oldValue) {
                if (newValue)
                    console.log("I see a data change in field!");
            }, true);
            scope.id = attrs.id;
            scope.open = function($event) {
                $event.preventDefault();
                $event.stopPropagation();

                scope.opened = true;
            };
        }
    }
});

commonDirectives.directive('cvInt', function () {
    return {
        restrict: 'E',
        scope: {
            intField: "=field"
        },
        templateUrl: 'partials/common/int.html',
        link: function(scope, element, attrs){
            console.log('cvInt', scope.field);
            scope.$watch('field', function(newValue, oldValue) {
                if (newValue)
                    console.log("I see a data change in field! - " + attrs.id);
            }, true);
            scope.id = attrs.id;
            scope.min = attrs.min;
            scope.max = attrs.max;
            scope.open = function($event) {
                $event.preventDefault();
                $event.stopPropagation();

                scope.opened = true;
            };
        }
    }
});